<template>
  <div>
    <BasicTable @register="registerTable">
      <template #action="{ record }"></template>
    </BasicTable>
    <EditModal @register="registerModal" @success="handleSuccess" />
  </div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
  name: 'SysTreeDict',
});
</script>
<script lang="ts" setup>
import { BasicTable, useTable, TableAction } from '@/components/Table';
import { getByPidAll, del } from '@/api/sys/sysTreeDictManage';
import { useModal } from '@/components/Modal';
import EditModal from './EditModal.vue';
import { useMessage } from '@/hooks/web/useMessage';
import { columns, searchFormSchema } from './data';
const { createMessage } = useMessage();
const [registerModal, { openModal }] = useModal();
const [registerTable, { reload }] = useTable({
  api: getByPidAll,
  columns,
  rowSelection: {
    type: 'checkbox',
  },
  rowKey: 'id',
  options: {
    delete: {
      show: true,
      api: del,
    },
    add: {
      show: true,
      overFunction: () => {
        openModal(true, {
          isUpdate: false,
        });
      },
    },
    edit: {
      show: true,
      overFunction: ({ record }) => {
        openModal(true, {
          record,
          isUpdate: true,
        });
      },
    },
    export: {
      show: false,
    },
  },
  isTreeTable: true,
  formConfig: {
    labelWidth: 120,
    schemas: searchFormSchema,
    baseColProps: { span: 12 },
  },
  useSearchForm: true,
  showTableSetting: true,
  pagination: false,
  bordered: true,
  showIndexColumn: false,
  actionColumn: {
    width: 120,
    title: '操作',
    dataIndex: 'action',
    slots: { customRender: 'action' },
    fixed: 'right',
  },
});
function handleEdit(record: Recordable) {
  openModal(true, {
    record,
    isUpdate: true,
  });
}
function handleDelete(record: Recordable) {
  del([record.id]).then(() => {
    createMessage.success(`删除成功`);
    reload();
  });
}
function handleSuccess() {
  reload();
}
</script>
